package com.example.pkmedical.Activity.weight.weightdevice;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.example.pkmedical.APP.MyApp;
import com.example.pkmedical.Base.BaseActivity;
import com.example.pkmedical.MainActivity;
import com.example.pkmedical.R;
import com.example.pkmedical.Utils.CommandUtil;
import com.example.pkmedical.Utils.SPUtils;

import java.text.DecimalFormat;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class NewUserWeightActivity extends BaseActivity {

    @BindView(R.id.newuser_weight_weight_one)
    TextView newuserWeightWeightOne;
    @BindView(R.id.newuser_weight_time_one)
    TextView newuserWeightTimeOne;
    @BindView(R.id.newuser_weight_weight_two)
    TextView newuserWeightWeightTwo;
    @BindView(R.id.newuser_weight_time_two)
    TextView newuserWeightTimeTwo;
    @BindView(R.id.newuser_weight_initial_weight)
    TextView newuserWeightInitialWeight;
    @BindView(R.id.newuser_weight_ok_button)
    Button newuserWeightOkButton;
    @BindView(R.id.newuser_weight_cancle_button)
    Button newuserWeightCancleButton;
    @BindView(R.id.newuser_weight_re_button)
    Button newuserWeightReButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_newuserweight);
        ButterKnife.bind(this);
    }

    @Override
    public void initData() {

    }

    @Override
    public void initView() {
        Log.d("yangshuo000000000",
                "1:" + SPUtils.getInstance().getString("user_difference_weight_all")
                        + "/" + "2:" + SPUtils.getInstance().getString("user_last_weight")
                        + "/" + "3:" + SPUtils.getInstance().getString("user_now_weight"));
        DecimalFormat df = new DecimalFormat("#.00");
        if (0 == CommandUtil.COMPANY_TYPE) {
            if ("0".equals(SPUtils.getInstance().getString("user_difference_weight_all"))) {
                newuserWeightWeightTwo.setText(Float.parseFloat(SPUtils.getInstance().getString("user_last_weight")) + " KG");
                newuserWeightWeightOne.setText(SPUtils.getInstance().getString("user_now_weight") + "KG");
            } else {
                newuserWeightWeightOne.setText(df.format(Float.parseFloat(SPUtils.getInstance().getString("user_now_weight")) - Float.parseFloat(SPUtils.getInstance().getString("user_difference_weight_all"))) + "KG");
                newuserWeightWeightTwo.setText(df.format(Float.parseFloat(SPUtils.getInstance().getString("user_last_weight")) - Float.parseFloat(SPUtils.getInstance().getString("user_difference_weight_all"))) + " KG");

            }
            newuserWeightInitialWeight.setText(getString(R.string.weight_device_initial) + SPUtils.getInstance().getString("user_first_weight") + " KG");
        } else {
            if ("0".equals(SPUtils.getInstance().getString("user_difference_weight_all"))) {
                newuserWeightWeightOne.setText(Float.parseFloat(SPUtils.getInstance().getString("user_now_weight")) * 2 + " LB");
                newuserWeightWeightTwo.setText(Float.parseFloat(SPUtils.getInstance().getString("user_last_weight")) * 2 + " LB");
            } else {
                float mWeight = Float.parseFloat(SPUtils.getInstance().getString("user_now_weight")) - Float.parseFloat(SPUtils.getInstance().getString("user_difference_weight_all"));
                newuserWeightWeightOne.setText(df.format(mWeight * 2) + " LB");
                Float db;
                db = Float.parseFloat(SPUtils.getInstance().getString("user_last_weight")) * 2 - Float.parseFloat(SPUtils.getInstance().getString("user_difference_weight_all")) * 2;
                newuserWeightWeightTwo.setText(df.format(db) + "LB");
            }
            newuserWeightInitialWeight.setText(getString(R.string.weight_device_initial) + Float.parseFloat(SPUtils.getInstance().getString("user_first_weight")) * 2 + " LB");
        }


    }

    @Override
    protected void onResume() {
        super.onResume();
        newuserWeightTimeOne.setText(SPUtils.getInstance().getString("Last_time"));
        newuserWeightTimeTwo.setText(SPUtils.getInstance().getString("Initial_time"));
    }

    @Override
    public void initPresenter() {

    }

    @Override
    public void showDialog(String... msg) {

    }

    @OnClick({R.id.newuser_weight_ok_button, R.id.newuser_weight_cancle_button, R.id.newuser_weight_re_button})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.newuser_weight_ok_button:
//                startActivity(new Intent(MyApp.getAppContext(), MainActivity.class));
                NewUserWeightActivity.this.finish();
                break;
            case R.id.newuser_weight_cancle_button:
                NewUserWeightActivity.this.finish();
                break;
            case R.id.newuser_weight_re_button:
                startActivity(new Intent(MyApp.getAppContext(), WeightAgainActivity.class));
                NewUserWeightActivity.this.finish();
                break;

        }
    }
}
